package com.cskaoyan.controller.admin.promotion;
/*
 * @Auther:王贲
 * @Date:2022/9/6
 * @Description:
 * @VERSON:1.8
 */

import com.cskaoyan.bean.MarketAd;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.admin.promotion.AdminAdDeleteVO;
import com.cskaoyan.bean.vo.admin.promotion.AdminAdInsertVO;
import com.cskaoyan.service.admin.promotion.AdminAdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cskaoyan.bean.common.BaseRespVo;

@RestController
@RequestMapping("admin/ad")
public class AdminAdController {

    @Autowired
    AdminAdService adminAdService;

    /**
     * @return com.cskaoyan.bean.common.BaseRespVo
     * @description : TODO 此方法为广告管理页面进入的方法
     * admin/ad/list?page=1&limit=20&sort=add_time&order=desc
     * @author wang'ben
     * @date 2022/9/6 20:09
     */
    @GetMapping("list")
    public BaseRespVo listAd(BasePageInfo basePageInfo, String name, String content) {
        // 通过basePageInfo接收传进来的get请求参数，通过CommonData接收并返回给浏览器响应
        CommonData commonData = adminAdService.selectAdInfo(basePageInfo, name, content);
        return BaseRespVo.ok(commonData);
    }


    /**
     * @return com.cskaoyan.bean.vo.admin.promotion.AdminAdDeleteVO
     * @description : TODO 广告的删除
     * @author wang'ben
     * @date 2022/9/7 11:41
     */
    @PostMapping("delete")
    public AdminAdDeleteVO deleteAd(@RequestBody MarketAd marketAd) {
        adminAdService.deleteAdInfo(marketAd);
        return AdminAdDeleteVO.ok("成功");
    }

    /**
     * @return com.cskaoyan.bean.common.BaseRespVo
     * @description : TODO 广告的增加
     * @author wang'ben
     * @date 2022/9/7 17:26
     */
    @PostMapping("create")
    public BaseRespVo createAd(@RequestBody MarketAd marketAd) {
        adminAdService.insert(marketAd);
        return BaseRespVo.ok(marketAd);
    }

    /**
     * @description : TODO 广告的更新编辑
     * @return com.cskaoyan.bean.common.BaseRespVo
     * @author wang'ben
     * @date 2022/9/7 19:44
     */
    @PostMapping("update")
    public BaseRespVo updateAd(@RequestBody MarketAd marketAd) {
        adminAdService.update(marketAd);
        return BaseRespVo.ok(marketAd);
    }
}
